<?php

defined('MYLITS') ? '' : exit('No direct script access allowed');

/**
 * @version     1.0.0
 * @package     mylits engine
 * @license     GNU General Public License version 3
 * @author      Arfan Fudyartanto D N <arfan@mylits.com> - http://engine.mylits.com
 */
class Mylits_User {

    public static $guest = true;
    public static $data;
    private static $instance;

    function __construct() {
        if (isset($_SESSION['userData'])) {
            self::$data = unserialize($_SESSION['userData']);
            self::$guest = false;
        }
    }

    /**
     * This method will return Mylits_User object
     * 
     * @return user Mylits_User
     */
    public static function getInstance() {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * Method to get group list of current user
     * 
     * @return array -> List group id of current user
     */
    public static function getGroupList() {
        $result = array();
        if (!self::$guest) {
            $model = Mylits_Loader::getModel('main', ENGINE_DIR . '/core/models/main.mdls.php');
            $userId = self::$data->id;
            $result = $model->getUserGroupList($userId);
        }
        return $result;
    }

    /**
     * Method to change user to another user
     * 
     * @todo select user from database, load as object, assign result as method paramater
     * @param object user
     */
    public static function changeUser($newUserObj) {
        self::$data = $newUserObj;
        $_SESSION['userData'] = serialize($newUserObj);
    }

}

?>
